package com.huafeng.controller;

import com.huafeng.annotations.Log;
import com.huafeng.model.base.Result;
import com.huafeng.model.entity.SysOperLog;
import com.huafeng.model.enums.OperationTypeEnum;
import com.huafeng.model.enums.ResultCodeEnum;
import com.huafeng.model.exception.BusinessException;
import com.huafeng.model.vo.SysOperLogQueryVo;
import com.huafeng.service.SysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 花风
 * @date 2023/8/18 20:28
 * @Description SysOperLogController
 */
@Api(tags = "操作日志管理")
@RestController
@RequestMapping("admin/system/sysOperLog")
public class SysOperLogController {
    @Resource
    private SysOperLogService sysOperLogService;

    @Log(model = "操作日志管理",operationType = OperationTypeEnum.GET)
    @ApiOperation("分页条件查询操作日志")
    @GetMapping("page")
    public Result queryOperLogByPage(SysOperLogQueryVo sysOperLogQueryVo){
        return sysOperLogService.queryOperLogByPage(sysOperLogQueryVo);
    }

    @Log(model = "操作日志管理",operationType = OperationTypeEnum.GET)
    @ApiOperation("查询操作日志详情")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        SysOperLog sysOperLog = sysOperLogService.query().eq("id", id).one();
        if (sysOperLog == null){
            throw new BusinessException(ResultCodeEnum.DATA_ERROR);
        }

        return Result.ok(sysOperLog);
    }

    @Log(model = "操作日志管理",operationType = OperationTypeEnum.EXPORT)
    @ApiOperation("导出操作日志")
    @PostMapping("export")
    public void export(HttpServletResponse response){
        sysOperLogService.export(response);
    }


}
